#include "applyfriendlist.h"
#include <QScrollBar>
#include <QWheelEvent>
ApplyFriendList::ApplyFriendList(QWidget *parent)
    : QListWidget(parent)
{
    this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    this->horizontalScrollBar()->setVisible(false);
    this->viewport()->installEventFilter(this);
}

bool ApplyFriendList::eventFilter(QObject *watched, QEvent *event)
{
    if (watched == this->viewport()) {
        if (event->type() == QEvent::Enter) {
            this->horizontalScrollBar()->setVisible(true);
            return true;
        }
        if (event->type() == QEvent::Leave) {
            this->horizontalScrollBar()->setVisible(false);
            return true;
        }
        if (event->type() == QEvent::MouseButtonPress) {
            emit sig_showSearch(false);
        }
        if (event->type() == QEvent::Wheel) {
            QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
            int numDegrees = wheelEvent->angleDelta().y() / 8;
            int numSteps = numDegrees / 15;
            // 设置滚动幅度
            this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() - numSteps);
            return true;
        }
    }
    return QListWidget::eventFilter(watched, event);
}
